﻿using CID.Domain.Infrastructure;
using CID.Tests.Support;
using NUnit.Framework;

namespace CID.Domain.Tests.Infrastructure.ParameterValue
{
    [TestFixture]
    public class ParameterValueConstructionTests : BaseFunctionalTests
    {
        #region DefaultParameterValue
        [Test]
        public void CreateDefaultParameterValue_BooleanParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.Boolean);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(default(bool), parameterValue.BooleanValue);
        }

        [Test]
        public void CreateDefaultParameterValue_DateTimeParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.DateTime);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(default(System.DateTime), parameterValue.DateTimeValue);
        }

        [Test]
        public void CreateDefaultParameterValue_DecimalParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.Decimal);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(default(decimal), parameterValue.DecimalValue);
        }

        [Test]
        public void CreateDefaultParameterValue_IntegerParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.Integer);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(default(int), parameterValue.IntegerValue);
        }

        [Test]
        public void CreateDefaultParameterValue_StringParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.String);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(string.Empty, parameterValue.StringValue);
        }

        [Test]
        public void CreateDefaultParameterValue_UniqueIdentifierParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.UniqueIdentifier);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(default(System.Guid), parameterValue.UniqueIdentifierValue);
        }

        [Test]
        public void CreateDefaultParameterValue_XmlParameter_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub(ParameterType.Xml);

            var parameterValue = new DefaultParameterValue(definition, parameter);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.IsNotNull(parameterValue.XmlValue);
            Assert.AreEqual("<?xml version=\"1.0\"?><root></root>", parameterValue.XmlValue.OuterXml);
        }
        #endregion

        #region EnvironmentParameterValue
        [Test]
        public void CreateEnvironmentParameterValue_ShouldSucceed()
        {
            var definition = StubsBuilder.BuildDeploymentDefinitionStub();
            var parameter = StubsBuilder.BuildParameterStub();
            var environment = Operations.StubsBuilder.BuildEnvironmentStub();

            var parameterValue = new EnvironmentParameterValue(definition, parameter, environment);

            Assert.AreEqual(definition, parameterValue.Definition);
            Assert.AreEqual(parameter, parameterValue.Parameter);
            Assert.AreEqual(environment, parameterValue.Environment);
        }
        #endregion
    }
}
